package soccer.view;

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;

public class AddPlayerTeamPanel extends JPanel {
	private JLabel playerLicenceNumber;
	private JLabel playerNameLabel;
	private JLabel playerSurnameLabel;
	private JLabel playerBirthPlacePanel;
	private JLabel playerBirthDatePanel;
	private JLabel  teamSelectLabel;
	private JComboBox teamsComboBox;
	private JTextField playerLicenceNumberText;
	private JTextField playerNameText;
	private JTextField playerSurnameText;
	private JTextField playerBirthPlaceText;
	private JFormattedTextField playerBirthDateText;
	private JButton addPlayerButton;
	private JPanel playerAgrementDatePanel;
	private JFormattedTextField  playerLicenceBeginText;
	private JFormattedTextField  playerLicenceFinishText;
	private JLabel label;
	private JLabel label2;
	private JButton btnBackToAdminOptionsSystem;
   
	/**
	 * Create the panel.
	 */
	public AddPlayerTeamPanel() {
		setLayout(null);
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
	    playerLicenceNumber = new JLabel("Licence Number :");
		playerLicenceNumber.setBounds(65, 43, 102, 14);
		add(playerLicenceNumber);
		
	    playerNameLabel = new JLabel("Player Name :");
		playerNameLabel.setBounds(65, 68, 86, 14);
		add(playerNameLabel);
		
	    playerSurnameLabel = new JLabel("Player Surname :");
		playerSurnameLabel.setBounds(65, 93, 102, 14);
		add(playerSurnameLabel);
		
	    playerBirthPlacePanel = new JLabel("Player Birth Place :");
		playerBirthPlacePanel.setBounds(65, 123, 112, 14);
		add(playerBirthPlacePanel);
		
		playerBirthDatePanel = new JLabel("Player Birth Date :");
		playerBirthDatePanel.setBounds(65, 151, 112, 14);
		add(playerBirthDatePanel);
		
		playerLicenceNumberText = new JTextField();
		playerLicenceNumberText.setBounds(177, 43, 102, 20);
		add(playerLicenceNumberText);
		playerLicenceNumberText.setColumns(10);
		
		playerNameText = new JTextField();
		playerNameText.setColumns(10);
		playerNameText.setBounds(177, 68, 102, 20);
		add(playerNameText);
		
		playerSurnameText = new JTextField();
		playerSurnameText.setColumns(10);
		playerSurnameText.setBounds(177, 93, 102, 20);
		add(playerSurnameText);
		
		playerBirthPlaceText = new JTextField();
		playerBirthPlaceText.setColumns(10);
		playerBirthPlaceText.setBounds(177, 120, 102, 20);
		add(playerBirthPlaceText);
		
		playerBirthDateText = new JFormattedTextField(sd);
		playerBirthDateText.setColumns(10);
		playerBirthDateText.setBounds(177, 148, 102, 20);
		add(playerBirthDateText);
		
		teamSelectLabel = new JLabel("Team Select :");
		teamSelectLabel.setBounds(65, 182, 102, 14);
		add(teamSelectLabel);
		
		teamsComboBox = new JComboBox();
		teamsComboBox.setMaximumRowCount(12);
		teamsComboBox.setBounds(177, 179, 102, 20);
		add(teamsComboBox);
		
	    addPlayerButton = new JButton("Add Player");
		addPlayerButton.setBounds(65, 310, 129, 23);
		add(addPlayerButton);
		
	    playerAgrementDatePanel = new JPanel();
		playerAgrementDatePanel.setBounds(65, 215, 239, 74);
		add(playerAgrementDatePanel);
		playerAgrementDatePanel.setLayout(null);
		playerAgrementDatePanel.setVisible(false);
		
		JLabel playerLicenceBeginDatePanel = new JLabel("Licence Begin Date :");
		playerLicenceBeginDatePanel.setBounds(0, 11, 110, 14);
		playerAgrementDatePanel.add(playerLicenceBeginDatePanel);
		
		JLabel playerLicenceFinishDatePanel = new JLabel("Licence Finish Date :");
		playerLicenceFinishDatePanel.setBounds(1, 36, 109, 14);
		playerAgrementDatePanel.add(playerLicenceFinishDatePanel);
		
		
		playerLicenceBeginText = new JFormattedTextField(sd);
		playerLicenceBeginText.setBounds(111, 8, 100, 20);
		playerAgrementDatePanel.add(playerLicenceBeginText);
		
		playerLicenceFinishText = new JFormattedTextField(sd);
		playerLicenceFinishText.setBounds(111, 33, 100, 20);
		playerAgrementDatePanel.add(playerLicenceFinishText);
		
		label2 = new JLabel("(*  yyyy-MM-dd)");
		label2.setBounds(111, 60, 95, 14);
		playerAgrementDatePanel.add(label2);
		
		label = new JLabel("(*  yyyy-MM-dd)");
		label.setBounds(303, 151, 95, 14);
		add(label);
		
		btnBackToAdminOptionsSystem = new JButton("Back to System");
		btnBackToAdminOptionsSystem.setBounds(218, 310, 117, 23);
		add(btnBackToAdminOptionsSystem);
	
	}
	public void addCoachBackToSystem(ActionListener l){
		btnBackToAdminOptionsSystem.addActionListener(l);
	}	
	
	public JButton getBtnBackToAdminOptionsSystem() {
		return btnBackToAdminOptionsSystem;
	}
	public void setBtnBackToAdminOptionsSystem(JButton btnBackToAdminOptionsSystem) {
		this.btnBackToAdminOptionsSystem = btnBackToAdminOptionsSystem;
	}
	public void fillComboBoxWithTeams(List<Map> teamsName){
	    Object[] items = new Object[teamsName.size()+1];
	       items[0] = "no team";
	    for(int i = 1; i < items.length; i++){
	    	Map item = teamsName.get(i-1);
	    	items[i] = item.get("teamName");
	    }
		DefaultComboBoxModel model = new DefaultComboBoxModel(items);
		teamsComboBox.setModel(model);
	}
	public  Object getSelectedTeamFromComboBox(){
		Object selectedItem = teamsComboBox.getSelectedItem();
		return selectedItem;
	}
	public void setPlayerAgrementPanelVisible(boolean x){
		 playerAgrementDatePanel.setVisible(x);
	}
	public void addTeamComboboxItemListener(ItemListener l){
		 teamsComboBox.addItemListener(l);
	}
	public void addPlayerButtonActionListener(ActionListener l){
		 addPlayerButton.addActionListener(l);
	}
	public JLabel getPlayerLicenceNumber() {
		return playerLicenceNumber;
	}
	public void setPlayerLicenceNumber(JLabel playerLicenceNumber) {
		this.playerLicenceNumber = playerLicenceNumber;
	}
	public JLabel getPlayerNameLabel() {
		return playerNameLabel;
	}
	public void setPlayerNameLabel(JLabel playerNameLabel) {
		this.playerNameLabel = playerNameLabel;
	}
	public JLabel getPlayerSurnameLabel() {
		return playerSurnameLabel;
	}
	public void setPlayerSurnameLabel(JLabel playerSurnameLabel) {
		this.playerSurnameLabel = playerSurnameLabel;
	}
	public JLabel getPlayerBirthPlacePanel() {
		return playerBirthPlacePanel;
	}
	public void setPlayerBirthPlacePanel(JLabel playerBirthPlacePanel) {
		this.playerBirthPlacePanel = playerBirthPlacePanel;
	}
	public JLabel getPlayerBirthDatePanel() {
		return playerBirthDatePanel;
	}
	public void setPlayerBirthDatePanel(JLabel playerBirthDatePanel) {
		this.playerBirthDatePanel = playerBirthDatePanel;
	}
	public JLabel getTeamSelectLabel() {
		return teamSelectLabel;
	}
	public void setTeamSelectLabel(JLabel teamSelectLabel) {
		this.teamSelectLabel = teamSelectLabel;
	}
	public JComboBox getTeamsComboBox() {
		return teamsComboBox;
	}
	public void setTeamsComboBox(JComboBox teamsComboBox) {
		this.teamsComboBox = teamsComboBox;
	}
	public JTextField getPlayerLicenceNumberText() {
		return playerLicenceNumberText;
	}
	public void setPlayerLicenceNumberText(JTextField playerLicenceNumberText) {
		this.playerLicenceNumberText = playerLicenceNumberText;
	}
	public JTextField getPlayerNameText() {
		return playerNameText;
	}
	public void setPlayerNameText(JTextField playerNameText) {
		this.playerNameText = playerNameText;
	}
	public JTextField getPlayerSurnameText() {
		return playerSurnameText;
	}
	public void setPlayerSurnameText(JTextField playerSurnameText) {
		this.playerSurnameText = playerSurnameText;
	}
	public JTextField getPlayerBirthPlaceText() {
		return playerBirthPlaceText;
	}
	public void setPlayerBirthPlaceText(JTextField playerBirthPlaceText) {
		this.playerBirthPlaceText = playerBirthPlaceText;
	}
	public JFormattedTextField getPlayerBirthDateText() {
		return playerBirthDateText;
	}
	public void setPlayerBirthDateText(JFormattedTextField playerBirthDateText) {
		this.playerBirthDateText = playerBirthDateText;
	}

	public void setAddPlayerButton(JButton addPlayerButton) {
		this.addPlayerButton = addPlayerButton;
	}

	public JButton getAddPlayerButton() {
		return addPlayerButton;
	}
	
	public  JPanel getPlayerAgrementDatePanel() {
		return playerAgrementDatePanel;
	}
	public void setPlayerAgrementDatePanel(JPanel playerAgrementDatePanel) {
		this.playerAgrementDatePanel = playerAgrementDatePanel;
	}
	public JFormattedTextField getPlayerLicenceBeginText() {
		return playerLicenceBeginText;
	}

	public void setPlayerLicenceBeginText(JFormattedTextField playerLicenceBeginText) {
		this.playerLicenceBeginText = playerLicenceBeginText;
	}

	public JFormattedTextField getPlayerLicenceFinishText() {
		return playerLicenceFinishText;
	}

	public void setPlayerLicenceFinishText(
			JFormattedTextField playerLicenceFinishText) {
		this.playerLicenceFinishText = playerLicenceFinishText;
	}
}
